/*
* @Author: dengjiayao
* @Date:   2017-10-27 09:41:13
* @Last Modified by:   dengjiayao
* @Last Modified time: 2017-10-27 10:34:23
*/

import { showMsg, guideQuery, guideUpdate } from '../../vuex/action'
export default {
  name: 'guide-list',
  vuex: {
    actions: {
      xQuery: guideQuery,
      xUpdate: guideUpdate,
      xShowMsg: showMsg
    }
  },
  data() {
    return {
      guide0: {},
      guide1: {}
    }
  },
  created() {
    this.query(0)
    this.query(1)
  },
  methods: {
    query(position) {
      this.xQuery({
        position: position
      })
        .then(res => {
          this['guide' + position] = res.list[0]
        })
        .catch(res => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    submit(position) {
      let form = this['guide' + position]
      this.xUpdate(form).catch(res => {
        this.xShowMsg({
          type: 'danger',
          content: res.error_msg
        })
      })
    }
  }
}
